#!/bin/sh

if [ $# != 2 ]; then
    echo "sh get-android-cpu.sh deviceId appName"
    exit 1;
fi

deviceId=$1
appName=$2
currentDir=$(cd "$(dirname "$0")"; pwd)
echo "currentDir:"$currentDir

datDir=$currentDir/../../../target/android-info/cpu/dat
htmlDir=$currentDir/../../../target/android-info/cpu/html

if [ ! -d "$datDir" ]; then
    mkdir -p $datDir
fi
if [ ! -d "$htmlDir" ]; then
    mkdir -p $htmlDir
fi

while true
do
    adb -s $deviceId shell top -n 1 | grep $appName| awk '{print $3" "$10}' >> $datDir/cpu.dat
done